#!/bin/bash

# NB Cloud Hub Gateway 启动脚本
# 
# 使用方法:
#   ./start.sh [profile] [port]
#
# 示例:
#   ./start.sh dev 8080
#   ./start.sh prod 8080

PROFILE=${1:-dev}
PORT=${2:-8080}
APP_NAME="nb-cloud-hub-gateway"
JAR_FILE="target/app-1.0-SNAPSHOT.jar"

echo "================================================"
echo "启动 $APP_NAME"
echo "环境: $PROFILE"
echo "端口: $PORT"
echo "================================================"

# 检查Java环境
if ! command -v java &> /dev/null; then
    echo "错误: 未找到Java环境，请安装Java 17或更高版本"
    exit 1
fi

# 检查JAR文件
if [ ! -f "$JAR_FILE" ]; then
    echo "错误: 未找到JAR文件 $JAR_FILE"
    echo "请先运行: mvn clean package"
    exit 1
fi

# 创建日志目录
mkdir -p logs

# 启动应用
echo "正在启动应用..."
java -jar \
    -Dspring.profiles.active=$PROFILE \
    -Dserver.port=$PORT \
    -Dfile.encoding=UTF-8 \
    -Xms512m \
    -Xmx1024m \
    $JAR_FILE

echo "应用已启动"
echo "健康检查: http://localhost:$PORT/api/status/health"
echo "应用信息: http://localhost:$PORT/api/status/info" 